package com.chujian.Adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.chujian.Utils.ImageLoader;
import com.chujian.model.Food;
import com.chujian.orderingsystem.R;

public class FoodListAdapter extends BaseAdapter{
	private LayoutInflater mLayoutInflater;
	private List<Food> mDataList;
	private Context context;
	ImageLoader mImageLoader;
	public FoodListAdapter(List<Food> mDataList, Context context) {
		super();
		this.mDataList = mDataList;
		this.context = context;
		mLayoutInflater=LayoutInflater.from(context);
		mImageLoader=new ImageLoader();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mDataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=mLayoutInflater.inflate(R.layout.food_list_item, null);
			holder.ivImage=(ImageView) convertView.findViewById(R.id.iv_fli_food);
			holder.tvName=(TextView) convertView.findViewById(R.id.tv_fli_food_name);
			holder.tvPrice=(TextView) convertView.findViewById(R.id.tv_fli_price);
			holder.tvUnit=(TextView) convertView.findViewById(R.id.tv_fli_unit);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
//		处理图片
		String url=mDataList.get(position).getFoodUrl();
		holder.ivImage.setTag(url);//把图片地址与url绑定
		if(!url.equals("")||!url.equals(null)){
			mImageLoader.showImageByAsyncTask(holder.ivImage,url);
		}
//		处理其他文字数据
		holder.tvName.setText(mDataList.get(position).getFoodName());
		holder.tvPrice.setText(""+mDataList.get(position).getFoodPrice());
		holder.tvUnit.setText("/"+mDataList.get(position).getFoodUnit());
		
		
		return convertView;
	}
	class ViewHolder{
		public ImageView ivImage;
		public TextView tvName;
		public TextView tvPrice;
		public TextView tvUnit;
		
	}
}
